"""
-*- coding: utf-8 -*-
@File  : generate_config_file.py
@author: ZhenyuYang
@Time  : 2023/04/06 21:45
"""
# raw_file = "../tools/mmaction2/configs/recognition/c3d/c3d_sports1m_16x1x1_45e_MEGC2019_rgb.py"
# raw_file = "../tools/mmaction2/configs/recognition/c3d/c3d_sports1m_16x1x1_45e_MEGC2019_shuffled_rgb.py"
raw_file = "../tools/mmaction2/configs/recognition/tsn/tsn_r50_1x1x3_75e_MEGC2019_rgb.py"
# raw_file = "../tools/mmaction2/configs/recognition/tsm/tsm_r50_1x1x8_50e_MEGC2019_test_rgb.py"
# raw_file = "../tools/mmaction2/configs/recognition/tsn/tsn_r50_1x1x3_75e_CASME2_rgb.py"
# raw_file = "../tools/mmaction2/configs/recognition/tsn/tsn_r50_1x1x3_75e_SMIC_rgb.py"
# raw_file = "../tools/mmaction2/configs/recognition/tsn/tsn_r50_1x1x3_75e_SAMM_rgb.py"
cross = 5
flow = False
with open(raw_file, "r") as f:
    raw_config = f.readlines()
for c in range(cross):
    config = list(map(lambda x: x.replace("split = 1", "split = {}".format(c+1)), raw_config))
    if flow:
        config = list(map(lambda x: x.replace("rawframes", "flows".format(c+1)), config))
        config = list(map(lambda x: x.replace("rgb", "flow".format(c+1)), config))
        file = "{}_flow_split{}.py".format(raw_file.split("_rgb")[0], c+1)
    else:
        file = "{}_split{}.py".format(raw_file.split(".py")[0], c+1)
    with open(file, "w") as f:
        f.writelines(config)
flow = True
with open(raw_file, "r") as f:
    raw_config = f.readlines()
for c in range(cross):
    config = list(map(lambda x: x.replace("split = 1", "split = {}".format(c+1)), raw_config))
    if flow:
        config = list(map(lambda x: x.replace("rawframes", "flows".format(c+1)), config))
        config = list(map(lambda x: x.replace("rgb", "flow".format(c+1)), config))
        file = "{}_flow_split{}.py".format(raw_file.split("_rgb")[0], c+1)
    else:
        file = "{}_split{}.py".format(raw_file.split(".py")[0], c+1)
    with open(file, "w") as f:
        f.writelines(config)



cross = 5
flow = True
with open(raw_file, "r") as f:
    raw_config = f.readlines()
for c in range(cross):
    config = list(map(lambda x: x.replace("split = 1", "split = {}".format(c+1)), raw_config))
    if flow:
        config = list(map(lambda x: x.replace("rawframes", "flows".format(c+1)), config))
        config = list(map(lambda x: x.replace("rgb", "flow".format(c+1)), config))
        file = "{}_flow_split{}.py".format(raw_file.split("_rgb")[0], c+1)
    else:
        file = "{}_split{}.py".format(raw_file.split(".py")[0], c+1)
    with open(file, "w") as f:
        f.writelines(config)
flow = True
with open(raw_file, "r") as f:
    raw_config = f.readlines()
for c in range(cross):
    config = list(map(lambda x: x.replace("split = 1", "split = {}".format(c+1)), raw_config))
    if flow:
        config = list(map(lambda x: x.replace("rawframes", "flows".format(c+1)), config))
        config = list(map(lambda x: x.replace("rgb", "flow".format(c+1)), config))
        file = "{}_flow_split{}.py".format(raw_file.split("_rgb")[0], c+1)
    else:
        file = "{}_split{}.py".format(raw_file.split(".py")[0], c+1)
    with open(file, "w") as f:
        f.writelines(config)